package com.nowcoder.community.util;

import com.nowcoder.community.entity.User;
import org.springframework.stereotype.Component;

/**
 * threadLocal 进行持有用户的信息，不使用 session
 * @BelongsProject: community
 * @BelongsPackage: com.nowcoder.community.util
 * @Author: Master_XXJS
 * @CreateTime: 2022-09-26  15:41
 * @Description: TODO
 * @Version: 1.0
 */
@Component
public class HostHolder {

    private ThreadLocal<User> users = new ThreadLocal<>();

    public void setUser(User user){
        users.set(user);
    }

    public User getUser(){
        return users.get();
    }

    public void clear(){
        users.remove();
    }
}

